#include <bits/stdc++.h>

using namespace std;

long long n[30] , m[30] , L[30] , V[30] , d[30][100010] , u[30][100010] , a[30][100010] , p[30][100010] , tong[30][100010];

int main()
{
	freopen("detect.in" , "r" , stdin);
	freopen("detect.out" , "w" , stdout);
	long long T;
	cin >> T;
	for (long long i = 1 ; i <= T ; i++)
	{
		cin >> n[i] >> m[i] >> L[i] >> V[i];
		long long cnt = 0;
		for (long long j = 1 ; j <= n[i] ; j++)
		{
			cin >> d[i][j] >> u[i][j] >> a[i][j];
		}
		for (long long j = 1 ; j <= m[i] ; j++)
		{
			cin >> p[i][j];
		}
		long long maxtong = 0;
		for (long long j = 1 ; j <= n[i] ; j++)
		{
			if (u[i][j] > V[i])
			{
				long long kaishi = -1;
				for (long long k = 1 ; k <= m[i] ; k++)
				{
					if (kaishi != -1)
					{
						tong[i][k]++;
						if (tong[i][k] > maxtong)
						{
							maxtong = tong[i][k];
						}
					}
					else if (p[k] >= d[j])
					{
						kaishi = k;
						tong[i][k]++;
						if (tong[i][k] > maxtong)
						{
							maxtong = tong[i][k];
						}
					}
				}
				cnt++;
			}
		}
		cout << cnt << " ";
		if (maxtong != cnt)
			cout << m - 1 - (cnt - maxtong) << endl;
	}
	return 0;
}
